package org.huang.spock.spring.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.huang.spock.spring.bo.Dept;
import org.huang.spock.spring.param.QueryDeptPageParam;

import java.util.List;

/**
 * @描述： MYBATIS 纯接口+ 注解的方式
 * @作者: Mr.huang
 * @创建时间: 2017/8/21 18:19
 * @版本: 1.0
 */
@Mapper
public interface DeptAnnoMapper {

    @Select("select * from t_dept")
    List<Dept> findAll();

    @Select("select * from t_dept where code like CONCAT('%',#{code},'%')")
    List<Dept> findAllByCodeLike(@Param("code") String code);

    @Select("select * from t_dept where code=#{code} limit 1")
    Dept getOne(@Param("code")String code);

    @Select("select * from t_dept where id=#{id} limit 1")
    Dept getById(@Param("id") Integer id);

    @Select({"<script>",
            " select * from t_dept WHERE 1 = 1 ",
            "<if test='paramPage.name != null'>and name like CONCAT('%',#{paramPage.name},'%') #{paramPage.name} </if>",
            "limit ${(paramPage.page - 1) * paramPage.pageSize},#{paramPage.pageSize}",
            "</script>"})
    List<Dept> listPaged(@Param("paramPage")QueryDeptPageParam paramPage);

    @Select("select * from t_dept where id=#{deptId} and name=#{name} and code =#{code}")
    Dept getParam(@Param("deptId") Integer deptId, @Param("name") String name, @Param("code") String code);
}
